﻿using MusicPlayerPlus.XiamiDecode.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace MusicPlayerPlus.XiamiDecode.Method
{
    public class GetListData
    {
        private string GetXmlUrl(string playerurl)
        {
            string str = "song/play?ids=/";

            int index = playerurl.IndexOf(str);
            if (index < 0)
            {
                return "";
            }
            return playerurl.Substring(0, index) + playerurl.Substring(index + str.Length);
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="xmlUrl"></param>
        /// <returns></returns>
        public TrackListInfo GetList(string xmlUrl)
        {
            try
            {
                xmlUrl = GetXmlUrl(xmlUrl);
                AMing.Core.Http.HttpHelper httpHelper = new AMing.Core.Http.HttpHelper();
                XmlDocument xmlDoc = new XmlDocument();
                string xmldata = httpHelper.Get(xmlUrl);
                xmlDoc.LoadXml(xmldata);
                TrackListInfo trackListInfo = LoadXmlData.LoadData(xmlDoc);

                return trackListInfo;

            }
            catch (Exception)
            {
                return new TrackListInfo();
            }
        }
    }
}
